#ifndef VIDEOPUSH_H
#define VIDEOPUSH_H

#include <QObject>
#include <QDialog>
#include <QThread>
#include<iostream>
#include <fstream>

extern "C" {
#include <libavdevice/avdevice.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}

class VideoPush: public QThread
{
    Q_OBJECT
public:
    explicit VideoPush(QObject* parent = nullptr);

    void run() override {
        _VideoPush();
    }

    void set_encoder(const QString _url);
    void stop_push();

signals:
    void requestStop(); // 定义一个请求停止的信号

private:
    void _VideoPush();

    void dshow();
    void set_decoder();
    void processing_frame();
    bool Error_detail(const char* err = "未知错误");

signals:
    void frameReady(const QImage* img);

private:
    std::atomic<bool>  stop = true;

    int errnum;
    char errbuf[20]{};
    std::string video{};
    int video_stream_index = -1;
    QString url;

    const AVInputFormat* inputFormat = nullptr;

    AVFormatContext* outputContext = nullptr;
    AVFormatContext* videoContext = nullptr;

    AVCodecContext* decoder = nullptr;//解码器
    AVCodecContext* encoder = nullptr;//编码器

    AVPacket* outPacket = nullptr;
    AVFrame* oFrame = nullptr;
    AVFrame* iFrame = nullptr;
    SwsContext* swsCtx = nullptr;
};

#endif // VIDEOPUSH_H
